﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>
</head>

<body>
  <%@ include file="/WEB-INF/include/header.jsp"%>
  <%@ include file="/WEB-INF/include/menu.jsp"%>

  <div class="container main-content">
    <div class="panel panel-default x-panel x-panel-layout">
      <div class="panel-heading">
        <ol class="breadcrumb">
          <li><a href="${ctx.host}/ecommerce">报表</a></li>
          <li class="active">报表</li>
        </ol>
      </div>

      <div class="panel-body">
        <div class="col-xs-2 x-panel-layout-left no-horizontal-padding">
          <%@ include file="/WEB-INF/include/submenu.jsp"%>
        </div>

        <div class="col-xs-10 x-panel-layout-right">
          <form id="bwh-report-form" class="form-horizontal" method="GET" action="${ctx.host}/bwh-reports/search">
            <div class="x-breadcrumb-wrapper">
              <div class="x-breadcrumb clearfix">
                <h2><i class="glyphicon glyphicon-fire"></i>&nbsp;&nbsp;<span>报表&nbsp;-&nbsp;三围数据报表</span></h2>
                <div class="pull-right">
                  <c:choose>
                    <c:when test="${not empty currentPrincipal.site}">
                      <span class="current-branchCode">${currentPrincipal.site.name}</span>
                    </c:when>
                    <c:otherwise>
                      <select name="site">
                        <option value="">所有门店</option>
                        <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                          <option value="${site.id}" ${site.id == selectedSiteId ? 'selected' : ''}>${site.name}</option>
                        </c:forEach>
                      </select>
                    </c:otherwise>
                  </c:choose>
                </div>
              </div>
            </div>

            <div class="x-breadcrumb-wrapper top-margin-20" style="position: relative;">
              <div class="form-group x-form-group">
                <label class="col-xs-2 control-label">学员手机号</label>
                <div class="col-xs-3" style="width: 30%;">
                  <input type="text" class="form-control" name="mobile" value="${param.mobile}" placeholder=""/>
                </div>
                <label class="col-xs-2 control-label">教练</label>
                <div class="col-xs-3" style="width: 30%;">
                  <select name="coach" class="form-control">
                    <option value=""></option>
                    <c:forEach var="principal" items="${persist.coaches(currentPrincipal.id, param.site)}">
                      <c:if test="${principal.value.coach}">
                        <option value="${principal.key}" ${param.coach == principal.key ? 'selected' : ''}>${principal.value.name}</option>
                      </c:if>
                    </c:forEach>
                  </select>
                </div>
              </div>

              <div class="form-group x-form-group">
                <label class="col-xs-2 control-label">记录时间</label>
                <div class="col-xs-3" style="width: 60%;">
                  <div class="input-group">
                    <input type="text" class="form-control date" name="from" value="${param.from}" placeholder="开始时间"/>
                    <span class="input-group-addon"></span>
                    <input type="text" class="form-control date" name="to" value="${param.to}" placeholder="结束时间"/>
                  </div>
                </div>
              </div>
              
              <div class="x-breadcrumb-wrapper clearfix" style="position: relative; margin-top: 15px;">
                <c:if test="${search and not empty bwhRecords}">
                  <div class="btn-group pull-left">
                    <a href="javascript:void(0);" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                      <i class="glyphicon glyphicon-arrow-down"></i>&nbsp;&nbsp;导出
                    </a>
                  </div>
                </c:if>
                
                <div class="btn-group pull-right">
                  <button id="search_btn" type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">查询</button>&nbsp;&nbsp;&nbsp;&nbsp;
                </div>
              </div>
            </div>
          </form>

          <c:if test="${search}">
            <table class="table table-striped table-hover x-table" style="margin-bottom:20px;">
              <thead>
                <tr>
                  <th>姓名<br/>手机</th>
                  <th>胸围</th>
                  <th>腰围</th>
                  <th>臀围（臂围）</th>
                  <th>记录时间</th>
                </tr>
              </thead>
              <tbody>
                <c:forEach var="result" items="${bwhRecords}">
                  <c:forEach var="bwhRecord" items="${result.value}" varStatus="status">
                    <tr>
                      <c:if test="${status.index == 0}">
                        <th rowspan="${fn:length(result.value)}">${persist.studentName(result.key)}<br/>${result.key}</th>
                      </c:if>
                      <td>${bwhRecord.bust}</td>
                      <td>${bwhRecord.waist}</td>
                      <td>${bwhRecord.hips}</td>
                      <td>${bwhRecord.recordTime}</td>
                    </tr>
                  </c:forEach>
                </c:forEach>
              </tbody>
            </table>
          </c:if>

          <div class="form-horizontal clearfix">
            <jsp:include page="/WEB-INF/include/page.jsp">
              <jsp:param name="url" value="orders-search" />
              <jsp:param name="queryString" value="${queryString}" />
            </jsp:include>
          </div>
        </div>
      </div>
    </div>
  </div>

  <%@ include file="/WEB-INF/include/script.jsp"%>

  <d:resource root="${ctx.resource}/build" type="script" src="js/page/report/bwh-report.js">
    <script type="text/javascript">
      require(['page/report/bwh-report'],function(page){
        page.init({
          today: '${today}'
        });
      })
    </script>
  </d:resource>
</body>
</html>